﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddDutyInfo.aspx.cs" Inherits="ZX.WebApp.EditWidows.OrganizationalManager.AddDutyInfo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery.form.js" type="text/javascript"></script>
    <link href="../../Styles/extendTable.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table class="tableContent" id="DutyInfoTable">
            <tr>
                <td style="height:30px; width:100px;">
                    &nbsp;职务类型
                </td>
                <td>
                    <input type="hidden" id="DutyTypeId" name="DutyTypeId" value='<%=DutyTypeIds %>' />
                    <input type="text" id="DutyTypeName" name="DutyTypeName"
                         readonly="readonly" style="height:20px;" value='<%=Titles %>'  />
                </td>
            </tr>
            <tr>
                <td style="height:30px;">
                    &nbsp;职务名称
                </td>
                <td>
                    <input type="text" id="Name" name="Name" maxlength="100"
                         style="height:20px;" runat="server" />
                    <span style="color: Red">*</span>
                </td>
            </tr>
            <tr>
                <td style="height:30px;">
                    &nbsp;顺序号
                </td>
                <td>
                    <input type="text" id="SequenceNo" name="SequenceNo" maxlength="100"
                            onkeyup="this.value=this.value.replace(/\D/g,'')" 
                            onafterpaste="this.value=this.value.replace(/\D/g,'')"
                            style="height:20px;" runat="server" />
                    <span style="color: Red">*</span>
                </td>
            </tr>
            <tr>
                <td style="height:30px;">
                    &nbsp;说明</td>
                <td>
                    <asp:TextBox ID="Remark" name="Remark" runat="server" 
                             MaxLength="200" TextMode="MultiLine" Width="250" Height="60"></asp:TextBox>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
<script type="text/javascript">
    var type = "<%=Type %>", Entity="<%=Entitys %>",
        flag = "<%=Flag %>", Url = "";
    <asp:Literal ID="EditTemplate" runat="server"></asp:Literal>

    $(document).ready(function () {
        if(flag=="0"){
            var obj = document.getElementById("DutyInfoTable"); //得到DIV对象
            var s = obj.getElementsByTagName("select");
            var e = obj.getElementsByTagName("input");
            var t = obj.getElementsByTagName("textarea");
            for (var j = 0; j < s.length; j++) {
                $("#" + s[i].id + "").attr("readonly", "readonly");
            }
            for (var i = 0; i < e.length; i++) {
                $("#" + e[i].id + "").attr("readonly", "readonly");
            }
            for (var k = 0; k < t.length; k++) {
                $("#" + t[k].id + "").attr("readonly", "readonly");
            }
        }
    });

    function Save() {
        var vName = $("#Name").val();
        var vSequenceNo = $("#SequenceNo").val();
        var vRemark = $("#Remark").val();
        if (vName == "") {
            alert("职务名称不能为空!");
            $("#Name").focus();
            return;
        } else if (vSequenceNo == "") {
            alert("顺序号不能为空!");
            $("#SequenceNo").focus();
            return;
        } else {
            $("#DutyInfoTable").SetFormValueToObject(instance[0]);
            var json = $.toJSON(instance[0]).replace(/'/g, "[B]");
            if(type==0){  //新增
                Url = "DataProcessin.aspx?entity=" + Entity + "&action=Insert&json=" + encodeURI(json);
            } else { //修改
                Url = "DataProcessin.aspx?entity=" + Entity + "&action=Update&json=" + encodeURI(json);
            }
            SaveData();
        }
    }
    function SaveData() {
        YAHOO.util.Connect.asyncRequest('POST', Url, {
            success: function (res) {
                var inventory;
                try {
                    inventory = res.responseText;
                    if (inventory == 1) {
                        alert("保存成功!");
                        parent.LoadDataById();
                    } else {
                        alert(inventory);
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
</script>
</html>
